﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 脚本功能：标题位置 显示相关的 控制
/// 添加对象：TitlePosShowCtr
/// </summary>
public class TitlePosShowCtr : MonoBehaviour {


    #region 数据定义和unity自带方法组
    private Image mStrShowBgImage;
    private Text mStrShowText;
    private Image mSpriteShowImage;
    private Text mBranchShowText;
    void Awake()
    {
        FindGo();
    }
    //void Start()
    //{
    //    //TitlePosShow(0, "sfs");
    //}
    //public Sprite[] yyyyy;
    //void Update()
    //{
    //    if (Input.GetKeyDown(KeyCode.A))
    //    {
    //        TitlePosShow(1, "", yyyyy[Random.Range(0, yyyyy.Length)]);
    //    }
    //}
    #endregion


    #region  私有方法组
    private void FindGo()
    {
        if (mStrShowBgImage == null)
        {
            mStrShowBgImage = transform.Find("StrShowBgImage").GetComponent<Image>();
        }
        if (mStrShowText == null)
        {
            mStrShowText = TransformHelper.FindChild(transform, "StrShowText").GetComponent<Text>();
        }
        if (mSpriteShowImage == null)
        {
            mSpriteShowImage = TransformHelper.FindChild(transform, "SpriteShowImage").GetComponent<Image>();
        }
        if (mBranchShowText == null)
        {
            mBranchShowText = TransformHelper.FindChild(transform, "BranchShowText").GetComponent<Text>();
        }
    }
    #endregion



    #region  公有方法组
    /// <summary>
    /// 标题位置显示  对应的东西
    /// </summary>
    /// <param name="type">0显示字符串   1显示图片  2 显示不定行数的text 文本</param>
    /// <param name="str">显示的字符串</param>
    /// <param name="sp">显示的图片</param>
    public void TitlePosShow(int type,string str = "",Sprite sp = null,params object[] paramsObj)
    {
        FindGo();
        switch (type)
        {
            case 0:
                mSpriteShowImage.gameObject.SetActive(false);
                mBranchShowText.gameObject.SetActive(false);

                bool needShow = !string.IsNullOrEmpty(str);
                mStrShowBgImage.gameObject.SetActive(needShow);
                mStrShowText.gameObject.SetActive(needShow);
                //这里需要将 文字的大小什么的吗？实在不行就放在 最后的参数里面
                mStrShowText.text = str;
                break;
            case 1:
                float spriteHeight = sp.texture.height;
                float spriteWidth = sp.texture.width;
                //print(" tupian   height"+ spriteHeight +"  ::  "+ spriteWidth);
                mSpriteShowImage.gameObject.SetActive(true);
                mBranchShowText.gameObject.SetActive(false);
                mStrShowText.gameObject.SetActive(false);
                mStrShowBgImage.gameObject.SetActive(false);

                RectTransform spriteRectTran = (mSpriteShowImage.transform) as RectTransform;
                spriteRectTran.sizeDelta = new Vector2(spriteWidth, spriteHeight);
                mSpriteShowImage.sprite = sp;
                break;

            case 2:
                //暂时支持两行
                string temp = str;
                if (temp.Contains("\n"))
                {
                    print("有分行的需求");
                    temp.Replace("\\n", "\n");
                }
                else
                {

                }
                mSpriteShowImage.gameObject.SetActive(false);
                mStrShowText.gameObject.SetActive(false);
                mStrShowBgImage.gameObject.SetActive(false);
                mBranchShowText.gameObject.SetActive(true);
                mBranchShowText.text = temp;
                break;

            default:
                break;
        }
    }
    #endregion



}
